package com.example.springbook1;

import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/login")
    public String login(String userName, String password, HttpSession session) {
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)) {
            return "用户名或密码错误";
        }
        if(!"admin".equals(userName) || !"admin".equals(password)) {
            return "密码错误";
        }
        //正确的情况
        session.setAttribute("userName",userName);
        return "";
    }
}
